
<script lang="ts" setup>
// 引入vue相关的文件
import { ref, toRefs, reactive, computed, watch, onMounted } from "vue";
const props = defineProps({
  bgHeight: {
    type: [String || Number],
    default: "",
  },
  bgColor: {
    type: String,
    default: "#fff",
  },
  morenSrc: {
    type: String,
    default: "",
  },
  sildeList: {
    type: Array as () => Array<Record<string, any>>,
    default: () => [],
  },
  show: {
    type: Number,
    default: 4,
  },
  autoPlay: {
    type: Boolean,
    default: false,
  },
});
const { bgHeight, bgColor, show, morenSrc, sildeList } = toRefs(props);

// 开始js代码
const bigSrc = ref("");
const count = ref(0);
// computed
const bigWrap = computed(() => {
  return {
    height: `${bgHeight.value}px`,
    background: `${bgColor.value}`,
  };
});
const listStyle = computed(() => {
  return {
    width: `${(screen.value + 1) * 1240}px`,
    left: `${count.value * 1240}px`,
  };
});
const screen = computed(() => Math.floor(sildeList.value.length / show.value));

// 切换大图片
const changeSrc = function (item: any) {
  bigSrc.value = item.bigSrc;
};
// 滑倒下一屏幕
const next = function () {
  if (count.value == -screen.value) {
    return count.value;
  }
  --count.value;
};
// 滑倒上一屏幕
const prev = function () {
  if (count.value == 0) {
    return (count.value = 0);
  }
  ++count.value;
};

watch(morenSrc, (val: string) => {
  bigSrc.value = val
})

onMounted(() => {
  bigSrc.value = morenSrc.value
})
</script>

<style scoped="">
.big-img-wrap {
  width: 100%;
}

.big-img-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  object-fit: contain;
}

.samll-img-wrap {
  margin-top: 28px;
}

.silde-list-wrap {
  position: relative;
  width: 1240px;
  height: 185px;
  overflow: hidden;
}

.silde-list {
  position: absolute;
  top: 0;
  left: 0;
  height: 185px;
  transition: all 0.36s ease;
}

.silde-item {
  margin-right: 9px;
  width: 303px;
  height: 185px;
  border-radius: 12px;
  overflow: hidden;
}

.silde-item:last-child {
  margin-right: 0;
}

.silde-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* 按钮样式 */
.cut-btn-wrap {
  padding-top: 56px;
}

.cut-btn {
  position: relative;
  width: 52px;
  height: 52px;
  font-size: 0;
  border: 1px solid #9195a3;
  border-radius: 12px;
  cursor: pointer;
  overflow: hidden;
}

.infont-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  font-size: 0px;
  transform: translate(-50%, -50%);
}

.infont-icon::before {
  content: "";
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  height: 0;
  width: 0;
  transition: all 0.2s cubic-bezier(0.785, 0.135, 0.15, 0.86);
}

.infont-icon::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 0px;
  height: 2px;
  background: #9195a3;
  display: inline-block;
  transform: translateY(-50%);
  transition: all 0.2s cubic-bezier(0.785, 0.135, 0.15, 0.86);
}

.cut-btn-left .infont-icon::before {
  margin-left: -4px;
  border-right: 6px solid #9195a3;
}

.cut-btn-right .infont-icon::before {
  border-left: 6px solid #9195a3;
}

.cut-btn-left .infont-icon::before {
  margin-left: -4px;
  border-right: 6px solid #9195a3;
}

.cut-btn-left .infont-icon::after {
  right: -10px;
}

.cut-btn-right .infont-icon::before {
  border-left: 6px solid #9195a3;
}

.cut-btn-right .infont-icon::after {
  left: -5px;
}

.cut-btn:hover .infont-icon::after {
  width: 14px;
}

.cut-btn-left:hover .infont-icon::before {
  margin-left: -8px;
}

.cut-btn-right:hover .infont-icon::before {
  margin-left: 8px;
}
</style>

<template>
  <section class="scale-wrap" v-if="sildeList.length">
    <section class="big-img-wrap flex-center" :style="bigWrap">
      <img :src="bigSrc" alt="">
    </section>
    <section class="samll-img-wrap flex justify-between">
      <section class="cut-btn-wrap">
        <section class="cut-btn cut-btn-left" @click="prev">
          <div class="infont-icon"></div>
        </section>
      </section>
      <section class="silde-list-wrap">
        <ul class="silde-list flex" :style="listStyle">
          <li class="silde-item" v-for="item in sildeList" :key="item.index" @click="changeSrc(item)">
            <img :src="item.src" :alt="item.alt">
          </li>
        </ul>
      </section>
      <section class="cut-btn-wrap">
        <section class="cut-btn cut-btn-right" @click="next">
          <div class="infont-icon"></div>
        </section>
      </section>
    </section>
  </section>
</template>